import $V from './$V';
import ema from './ema';

export default function trix(price, length, smoothLength) {
    let trixValue = $V.init(price.length,0);
    let matrixValue = $V.init(price.length,0);
    let tr = $V.init(price.length,0);
    tr = ema(ema(ema(price,length),length),length);

    trixValue = $V.copy_by_index(trixValue,2,$V.mul_constant($V.div($V.sub($V.subv(tr,1,price.length),$V.subv(tr,0,price.length-1)),$V.subv(price,0,price.length-1)),100));
    matrixValue = ema(trixValue,smoothLength);
    return { trixValue, matrixValue };
}
